<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>频率选择</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/allApp.css" />
		<link rel="stylesheet" href="css/css.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">频率选择</h1>
			<!--<a class="mui-icon-right-nav mui-pull-right">确定</a>-->
		</header>
		<div class="mui-content">
			<ul class="mui-table-view mui-table-view-radio">
				<li class="mui-table-view-cell mui-selected" data-type="0">
					<a class="mui-navigate-right">
						天
					</a>
				</li>
				<li class="mui-table-view-cell" data-type="1">
					<a class="mui-navigate-right">
						周
					</a>
				</li>
				<li class="mui-table-view-cell" data-type="2">
					<a class="mui-navigate-right">
						月
					</a>
				</li>
				<li class="mui-table-view-cell" data-type="3">
					<a class="mui-navigate-right">
						季度
					</a>
				</li>
				<li class="mui-table-view-cell" data-type="4">
					<a class="mui-navigate-right">
						特殊巡检
					</a>
				</li>
			</ul>
			<div class="btn">
				<button type="button" class="mui-btn mui-btn-primary mui-col-sm-12 mui-col-xs-12" id="sure">确定</button>
			</div>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/jquery-3.1.1.js"></script>
		<script type="text/javascript" src="../../js/mkeyplus.base.xunjian.js"></script>
		<script src="./js/websql.js"></script>
		<script>
			mui.init()
			var scancode;
			var opener;
			var rateid;
			var index;
			mui.plusReady(function() {
				self = plus.webview.currentWebview();
				scancode = self.scan;
				opener = self.opener()
				opener.close('none');
				console.log(localStorage.getItem("curentTime"));
				if(scancode.indexOf("\"")!=-1){
					scancode=scancode.replace(/\"/g, "");
				}
//				if(typeof(scancode) == "undefined")
				document.querySelector('#sure').addEventListener('tap', function() {
					index = $(".mui-content li.mui-selected").index();
					if (plus.networkinfo.getCurrentType()  ==  plus.networkinfo.CONNECTION_NONE)  {
						if(index != 4) {
							websqlOpenDB();               
							console.log("查找全部数据");    
							                                     
							websqlGetAData(sbInfoTable, scancode, index);
						} else {
							mui.toast('无网状态下不能特殊巡检哦~~')
						}
					} else {
						if(index != 4) {
							mui.baseApp.httpRequst('/api/v2/sbxj/createUserXj', {
								memberId: localStorage.getItem('userid'),
								scancode: scancode,
								rate: index
							}, function(res) {
								console.log("巡检项" + JSON.stringify(res));
								if(res.status == 200) {
									var data = res.data;
									if(data == null) {
										mui.toast(res.message,{type:'div'});
									} else {
										sure();
									}

								} else if(res.status == 400) {
									mui.toast(res.message,{type:'div'});
								} else if(res.status == 500) {
									mui.toast(res.message,{type:'div'});
								}

							}, function() {
								plus.nativeUI.closeWaiting();
								console.log("获取列表项失败");
							});
						} else {
							mui.baseApp.httpRequst('/api/v2/sbxj/findSbInfo', {
								scancode: scancode
							}, function(res) {
								console.log("特殊巡检项" + JSON.stringify(res));
								if(res.status == 200) {
									var data = res.data;
									if(data == null) {
										mui.toast(res.message,{type:'div'});
									} else {
										sure();
									}

								} else if(res.status == 400) {
									mui.toast(res.message,{type:'div'});
								} else if(res.status == 500) {
									mui.toast(res.message,{type:'div'});
								}

							}, function() {
								plus.nativeUI.closeWaiting();
								console.log("获取列表项失败");
							});
						}

					}
				})

			});

			function sure() {
				//				扫面时间
				var myDate = new Date(); //保存的日期时间
				var year = myDate.getFullYear(); //年
				var month = myDate.getMonth() + 1;
				var day = myDate.getDate();
				var hour = myDate.getHours(); //获取当前小时数(0-23)
				var mins = myDate.getMinutes(); //获取当前分钟数(0-59)
				var second = myDate.getSeconds(); //获取当前秒数(0-59)
				var months = (month < 10) ? ("0" + month) : month;
				var days = (day < 10) ? ("0" + day) : day;
				var hours = (hour < 10) ? ("0" + hour) : hour;
				var minss = (mins < 10) ? ("0" + mins) : mins;
				var seconds = (second < 10) ? ("0" + second) : second;
				console.log("月。。" + month + "日" + day.length)
				var smTime = year + "-" + months + "-" + days + " " + hours + ":" + minss + ":" + seconds;
				console.log(smTime);
				index = $(".mui-content li.mui-selected").index();
				console.log(index);
				if(index == "4") {
					mui.openWindow({
						id: "specialxunjian.html",
						url: "specialxunjian.html",
						/*waiting: {
							autoShow: false, //自动显示等待框，默认为true
						},*/
						extras: {
							scancode: scancode,
							index: index,
							smTime: smTime
						}
					});
				} else {
					mui.openWindow({
						id: "xianchangxunjian.html",
						url: "xianchangxunjian.html",
						extras: {
							scancode: scancode,
							index: index,
							smTime: smTime
						}
					});
				}

			}
			//			获取第一个表数据
			function success(sbInfo_) {
				var sbInfo_list = sbInfo_.List;
				console.log('sbInfo_list' + JSON.stringify(sbInfo_list));
				name = sbInfo_list.name;
				rateid = sbInfo_list.rateid;
				websqlGetAData_(jcxInfoTable, rateid);
			}
			//			获取第二个表数据
			function success_(jcxInfo) {
				var jcxInfo_list = jcxInfo.List;
				if(jcxInfo.List.length == 0) {
					mui.toast('当前频率下无数据');
				} else {
					sure();
				}

			}
		</script>
	</body>

</html>